package Server;

import global.global;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.hcmus.post2server.post2server;
import common.Store;

public class ConvertData {

	 public static JSONObject LoadDataSourcePostNew(String lat , String lng , String distance){
				JSONArray jsonRoot = new JSONArray();
				 JSONObject result = null;
				
			    	ArrayList<Store> lstStore = new ArrayList<Store>();
			    	
			    	lstStore = HandleServer.GetListStoreNearPosition("10.3435553","106.342455","500");
			    	//lstStore = HandleServer.GetListStoreNearPosition(lat,lng,distance);
					
			    	try{
			    		
			    		
			    		String id = "id";
			    		String name="name";
			    		String AddressShopping = "AddressShopping";
			    		String PromotionShopping= "PromotionShopping";
			    		String LocationType = "1";
			    		String ShopChainName = "ShopChainName";
			    		String Longitude= "Longitude";
			    		String Latitude= "Latitude";
			    		String Altitude= "12.1313";
			    		String imgUrl = "1";
			    		String type="";
			    		
			    		for(int i = 0 ; i< lstStore.size() ; i++){
			    			Store s = lstStore.get(i);
			    			id = String.valueOf(s.getId());
			    			type = String.valueOf(s.getType());
			    			name = s.getName();
			    			Latitude = s.getLat();
			    			Longitude = s.getLng();
			    			Altitude = "5";//s.getAlt();
			    			imgUrl = "1";
			    			LocationType = String.valueOf(s.getType());			    			
			    			PromotionShopping = s.getName();
			    			AddressShopping = s.getAddress();
			    			ShopChainName = "Demo";			    			
			    			JSONObject jOb = new JSONObject();
							jOb.put("ID",id); 
							jOb.put("Title", name);
							jOb.put("AddressShopping", AddressShopping);
							jOb.put("PromotionShopping", PromotionShopping);
							jOb.put("LocationType", LocationType);
							jOb.put("ShopChainName", ShopChainName);
							jOb.put("Longitude", Double.parseDouble(Longitude));
							jOb.put("Latitude", Double.parseDouble(Latitude));
							jOb.put("Altitude", Double.parseDouble(Altitude));
							jOb.put("ImgUrl", Integer.parseInt(imgUrl));
							jsonRoot.put(jOb);							
			    		}		    		
			    		 result = new JSONObject();
					    	try {
								result.put("DentifierDataSource", jsonRoot);
							} catch (JSONException e) { 
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
					   
			    	return result;
			    	
			    }catch(Exception e){
			    
			    }
				return result;
	    	}
}
